package com.ruoyi.submit.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.submit.domain.TQuestionSubmit;
import com.ruoyi.submit.service.ITQuestionSubmitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题目提交Controller
 * 
 * @author ruoyi
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/submit/submit")
public class TQuestionSubmitController extends BaseController
{
    @Autowired
    private ITQuestionSubmitService tQuestionSubmitService;

    /**
     * 查询题目提交列表
     */
    @PreAuthorize("@ss.hasPermi('submit:submit:list')")
    @GetMapping("/list")
    public TableDataInfo list(TQuestionSubmit tQuestionSubmit)
    {
        startPage();
        List<TQuestionSubmit> list = tQuestionSubmitService.selectTQuestionSubmitList(tQuestionSubmit);
        return getDataTable(list);
    }

    /**
     * 导出题目提交列表
     */
    @PreAuthorize("@ss.hasPermi('submit:submit:export')")
    @Log(title = "题目提交", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TQuestionSubmit tQuestionSubmit)
    {
        List<TQuestionSubmit> list = tQuestionSubmitService.selectTQuestionSubmitList(tQuestionSubmit);
        ExcelUtil<TQuestionSubmit> util = new ExcelUtil<TQuestionSubmit>(TQuestionSubmit.class);
        util.exportExcel(response, list, "题目提交数据");
    }

    /**
     * 获取题目提交详细信息
     */
    @PreAuthorize("@ss.hasPermi('submit:submit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tQuestionSubmitService.selectTQuestionSubmitById(id));
    }

    /**
     * 新增题目提交
     */
    @PreAuthorize("@ss.hasPermi('submit:submit:add')")
    @Log(title = "题目提交", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TQuestionSubmit tQuestionSubmit)
    {
        return toAjax(tQuestionSubmitService.insertTQuestionSubmit(tQuestionSubmit));
    }

    /**
     * 修改题目提交
     */
    @PreAuthorize("@ss.hasPermi('submit:submit:edit')")
    @Log(title = "题目提交", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TQuestionSubmit tQuestionSubmit)
    {
        return toAjax(tQuestionSubmitService.updateTQuestionSubmit(tQuestionSubmit));
    }

    /**
     * 删除题目提交
     */
    @PreAuthorize("@ss.hasPermi('submit:submit:remove')")
    @Log(title = "题目提交", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tQuestionSubmitService.deleteTQuestionSubmitByIds(ids));
    }
}
